var mailingAddress = "";//
var postalCode = "";
var addressee = "";
var addrTele = "";

var payType = "";
$(document).ready(function(){
	
	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/getOrdersByStudentId",
		async:false,
		data:{
			StudentId:student_id
		},
		success:function(result)
		{
			payType = result.extend.code;
		}
	});
	
	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/getStudentById",
		async:false,
		data:{
			StudentId:student_id
		},
		success:function(result)
		{
			var promiseType = result.extend.student.promiseType;
			if(promiseType==1 && payType==1)
				window.location.href = "affirmMess.html";
			
			var cardId = result.extend.student.cardId;
			var graduationType = result.extend.student.graduationType;
			var examineeType = result.extend.student.examineeType;
			
			document.getElementById("cardId").innerHTML = cardId;
			switch (graduationType)
			{
				case 1:
					document.getElementById("graduationType").innerHTML = '高中';
					break;
				case 2:
					document.getElementById("graduationType").innerHTML = '中等师范';
					break;
				case 3:
					document.getElementById("graduationType").innerHTML = '中等专业学校';
					break;
				case 4:
					document.getElementById("graduationType").innerHTML = '职业高中学校';
					break;
				case 5:
					document.getElementById("graduationType").innerHTML = '技工学校';
					break;
				case 6:
					document.getElementById("graduationType").innerHTML = '其他学校';
					break;
			}
			switch (examineeType)
			{
				case 1:
					document.getElementById("examineeType").innerHTML = '城市应届';
					break;
				case 2:
					document.getElementById("examineeType").innerHTML = '农村应届';
					break;
				case 3:
					document.getElementById("examineeType").innerHTML = '城市往届';
					break;
				case 4:
					document.getElementById("examineeType").innerHTML = '农村往届';
					break;
			}
			
			mailingAddress = result.extend.student.mailingAddress;//需要填写的值
			postalCode = result.extend.student.postalCode;
			addressee = result.extend.student.addressee;
			addrTele = result.extend.student.addrTele;
			
			if(mailingAddress != null && mailingAddress != "null" && mailingAddress)
			{
				document.getElementById("mailingAddress").value = mailingAddress;
				document.getElementById("postalCode").value = postalCode;
				document.getElementById("addressee").value = addressee;
				document.getElementById("addrTele").value = addrTele;
			}
		}
	});
});

function ok()
{
	var mailingAddress = document.getElementById("mailingAddress").value;
	var postalCode = document.getElementById("postalCode").value;
	var addressee = document.getElementById("addressee").value;
	var addrTele = document.getElementById("addrTele").value;
	
	if(mailingAddress != "")
		if(mailingAddress.length <= 40)
			if((/(^\d{6}$)/.test(postalCode)))
				if(addressee != "" && addressee.length<=4)
					if((/(^(1)\d{10}$)/.test(addrTele)))
						passByValue(mailingAddress,postalCode,addressee,addrTele);
					else
						alert("电话错误");
				else
					alert("请输入收件人并且字数在4以内");
			else
				alert("邮政编码错误");
		else
			alert("通知书邮寄地址多于40字内容")
	else
		alert("请输入通知书邮寄地址");
}

function passByValue(mailingAddress,postalCode,addressee,addrTele)
{
	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/updateStudent",
		async:true,
		data:{
			id:student_id,
			mailingAddress:mailingAddress,
			postalCode:postalCode,
			addressee:addressee,
			addrTele:addrTele
		},
		success:function(result)
		{
			if(result.code == 100)
			{
				window.location.href = "affirmMess.html";
			}
			else
			{
				alert(result.extend.code);
			}
		}
	});
}

function resetValue()
{
	document.getElementById("mailingAddress").value = "";
	document.getElementById("postalCode").value = "";
	document.getElementById("addressee").value = "";
	document.getElementById("addrTele").value = "";
}

function toMessageMessFill()
{
	if(mailingAddress)
	{
		if(postalCode)
			if(addressee)
				if(addrTele)
					window.location.href = "messageMessFill.html";
	}
	else
	{
		alert("请点击下一步");
	}
}

function toVolunteerMessFill()
{
	if(mailingAddress)
	{
		if(postalCode)
			if(addressee)
				if(addrTele)
					window.location.href = "volunteerMessFill.html";
	}
	else
	{
		alert("请点击下一步");
	}
}